package com.py.custom.tms.application.redis;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Scanner;

public class Client {

    public static void main(String[] args) throws Exception {
        // 1 nio socket
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.socket();
        socketChannel.configureBlocking(false);
        socketChannel.connect(new InetSocketAddress("127.0.0.1", 9907));
        // 完成连接
        socketChannel.finishConnect();

        while (true) {
            // 输入数据
            Scanner scanner = new Scanner(System.in);
            String line = scanner.nextLine();
            ByteBuffer byteBuffer = ByteBuffer.wrap(line.getBytes());

            // 2.发送数据
            socketChannel.write(byteBuffer);
            byteBuffer.clear();
            if (line.equals("bye")) {
                socketChannel.close();
                return;
            }
        }

    }
}
